package interpreter;

import Interfaces.Runner;
import grammar.FunLexer;
import grammar.FunParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

/**
 * Simple interpreter
 */
public class Interpreter implements Runner {
    @Override
    public String run(String program) {
        ANTLRInputStream input = new ANTLRInputStream(program);
        FunLexer lexer = new FunLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        FunParser parser = new FunParser(tokens);
        ParseTree tree = parser.program();
        System.out.println(tree.toStringTree(parser));

        TestFunVisitor visitor = new TestFunVisitor();
        return visitor.visit(tree).toString();
    }
}
